<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Change_password extends MX_Controller {

	public function __construct() {
		parent::__construct();
		
		
		$this->template->set_partial('header_search', 'header/header_search');
		$this->template->set_partial('nav_bar', 'header/nav_bar');
		$this->load->model('member/member_model');
		$this->load->model('member/profile_model');
		//$this->member_model->check_logedin();
		$this->member_model->check_logedin();
		
	}
	
	function index()
	{
		
		
		/*GET PROFILE ID*/
		$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
		
		if($isProfile){
			//$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			
			$data['profile']['info'] = $isProfile;
			//$data['profile_id'] = $profile_id;
			
		
		}else{
			$data['profile']['info'] = null;
		}
		/*GET PROFILE ID*/
		//$data['member_id'] = $member_id;

		if($this->member_model->getMember($this->session->userdata['mem_id'])){
			$data['member']['info'] = $this->member_model->getMember($this->session->userdata['mem_id']);
		}

		$this->template->set_layout('full_layout');
		//$this->member_model->check_logedin();
		
		$data['module_banner'] = FALSE;
		$data['module_recent_listing'] = TRUE;
		$data['module_news'] = FALSE;
		$this->template->build('change_password',$data);
	}
	
	function submit_password()
	{
		/*GET PROFILE ID*/
		/*$isProfile  = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id']);
	
		if($isProfile){
			$profile_id = $this->profile_model->getProfileByMemberID($this->session->userdata['mem_id'])->id;
			$data['profile_id'] = $profile_id;
	
	
		}else{
			$data['profile_id'] = null;
		}
		/*GET PROFILE ID*/
		//$data['member_id'] = $member_id;
	
		/*if($this->member_model->getMember($this->session->userdata['mem_id'])){
			$data['member']['info'] = $this->member_model->getMember($this->session->userdata['mem_id']);
		}
	*/
	
	if ($this->input->post('verify')) {
			$this->form_validation->set_rules('oldpass', 'Old Password', 'required|xss_clean');
			$this->form_validation->set_rules('newPass', 'New Password', 'required|xss_clean ');
			$this->form_validation->set_rules('repeatPass', 'Repeat New Password', 'required|xss_clean|matches[newPass]');
				
			if ($this->form_validation->run() == true) {
				
				if ($this->session->userdata('mem_password') == $this->input->post('oldpass')) {
					
					//print $this->session->userdata('mem_password');
					//die();
					
					$data=array('password'=>$this->input->post('newPass'));
					 
					//print_r($data);
					//die();
					$this->db->where('name',$this->session->userdata('mem_name'));
					$this->db->update('member',$data);
					$this->session->set_flashdata('message', 'Password Changed Sucessfully Login with new Password....!');
					redirect('member/change_password');
		
				} else {
					$this->session->set_flashdata('message', 'Old password is wrong!');
					redirect('member/change_password');
				}
			} else {
				$this->session->set_flashdata('message', 'Field is empty or new password is mismatched with confirm password! ');
				redirect('member/change_password');
			}
		}
		}
	}
	
	